import axios from 'axios'

const instance = axios.create({
    headers: {
        'X-Requested-With': 'XMLHttpRequest'
    },
    timeout: 3000,
    withCredentials: true,
});
instance.interceptors.request.use(function (config) {
    if (config.url.startsWith("/api")) {
        config.url = 'http://59.111.92.205:8088' + config.url;
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 响应拦截器
instance.interceptors.response.use(function (response) {
    if (response.status === 200) {
        return response.data;
    } else {
        console.error("请求错误")
        console.error(response)
    }
    return response;
}, function (error) {
    return Promise.reject(error);
});
export default instance;
